﻿/* 
  This file is part of the Hokkaido project - http://code.google.com/p/hokkaido/

  Based on the Processing project - http://processing.org
  
  Copyright (c) 2004-07 Ben Fry & Casey Reas
  Copyright (c) 2001-04 Massachusetts Institute of Technology

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Hokkaido.Core
{
    public abstract class PConstants {

      static public readonly int X = 0;  // model coords xyz (formerly MX/MY/MZ)
      static public readonly int Y = 1;
      static public readonly int Z = 2;

      static public readonly int R = 3;  // actual rgb, after lighting
      static public readonly int G = 4;  // fill stored here, transform in place
      static public readonly int B = 5;  // TODO don't do that anymore (?)
      static public readonly int A = 6;

      static public readonly int U = 7; // texture
      static public readonly int V = 8;

      static public readonly int NX = 9; // normal
      static public readonly int NY = 10;
      static public readonly int NZ = 11;

      static public readonly int EDGE = 12;


      // stroke

      /** stroke argb values */
      static public readonly int SR = 13;
      static public readonly int SG = 14;
      static public readonly int SB = 15;
      static public readonly int SA = 16;

      /** stroke weight */
      static public readonly int SW = 17;


      // transformations (2D and 3D)

      static public readonly int TX = 18; // transformed xyzw
      static public readonly int TY = 19;
      static public readonly int TZ = 20;

      static public readonly int VX = 21; // view space coords
      static public readonly int VY = 22;
      static public readonly int VZ = 23;
      static public readonly int VW = 24;


      // material properties

      // Ambient color (usually to be kept the same as diffuse)
      // fill(_) sets both ambient and diffuse.
      static public readonly int AR = 25;
      static public readonly int AG = 26;
      static public readonly int AB = 27;

      // Diffuse is shared with fill.
      static public readonly int DR = 3;  // TODO needs to not be shared, this is a material property
      static public readonly int DG = 4;
      static public readonly int DB = 5;
      static public readonly int DA = 6;

      // specular (by default kept white)
      static public readonly int SPR = 28;
      static public readonly int SPG = 29;
      static public readonly int SPB = 30;

      static public readonly int SHINE = 31;

      // emissive (by default kept black)
      static public readonly int ER = 32;
      static public readonly int EG = 33;
      static public readonly int EB = 34;

      // has this vertex been lit yet
      static public readonly int BEEN_LIT = 35;

      static public readonly int VERTEX_FIELD_COUNT = 36;


      // renderers known to processing.core

      static readonly String P2D    = "processing.core.PGraphics2D";
      static readonly String P3D    = "processing.core.PGraphics3D";
      static readonly String JAVA2D = "processing.core.PGraphicsJava2D";
      static readonly String OPENGL = "processing.opengl.PGraphicsOpenGL";
      static readonly String PDF    = "processing.pdf.PGraphicsPDF";
      static readonly String DXF    = "processing.dxf.RawDXF";


      // platform IDs for PApplet.platform

      static readonly int OTHER   = 0;
      static readonly int WINDOWS = 1;
      static readonly int MACOSX  = 2;
      static readonly int LINUX   = 3;

      static readonly String[] platformNames = {
        "other", "windows", "macosx", "linux"
      };


      static readonly float EPSILON = 0.0001f;


      // max/min values for numbers

      /**
       * Same as Float.MAX_VALUE, but included for parity with MIN_VALUE,
       * and to avoid teaching static methods on the first day.
       */
      static readonly float MAX_FLOAT = Float.MAX_VALUE;
      /**
       * Note that Float.MIN_VALUE is the smallest <EM>positive</EM> value
       * for a floating point number, not actually the minimum (negative) value
       * for a float. This constant equals 0xFF7FFFFF, the smallest (farthest
       * negative) value a float can have before it hits NaN.
       */
      static readonly float MIN_FLOAT = -Float.MAX_VALUE;
      /** Largest possible (positive) integer value */
      static readonly int MAX_INT = Integer.MAX_VALUE;
      /** Smallest possible (negative) integer value */
      static readonly int MIN_INT = Integer.MIN_VALUE;


      // useful goodness

      static readonly float PI = (float) Math.PI;
      static readonly float HALF_PI    = PI / 2.0f;
      static readonly float THIRD_PI   = PI / 3.0f;
      static readonly float QUARTER_PI = PI / 4.0f;
      static readonly float TWO_PI     = PI * 2.0f;

      static readonly float DEG_TO_RAD = PI/180.0f;
      static readonly float RAD_TO_DEG = 180.0f/PI;


      // angle modes

      //static readonly int RADIANS = 0;
      //static readonly int DEGREES = 1;


      // used by split, all the standard whitespace chars
      // (also includes unicode nbsp, that little bostage)

      static readonly String WHITESPACE = " \t\n\r\f\u00A0";


      // for colors and/or images

      static readonly int RGB   = 1;  // image & color
      static readonly int ARGB  = 2;  // image
      static readonly int HSB   = 3;  // color
      static readonly int ALPHA = 4;  // image
      static readonly int CMYK  = 5;  // image & color (someday)


      // image file types

      static readonly int TIFF  = 0;
      static readonly int TARGA = 1;
      static readonly int JPEG  = 2;
      static readonly int GIF   = 3;


      // filter/convert types

      static readonly int BLUR      = 11;
      static readonly int GRAY      = 12;
      static readonly int INVERT    = 13;
      static readonly int OPAQUE    = 14;
      static readonly int POSTERIZE = 15;
      static readonly int THRESHOLD = 16;
      static readonly int ERODE     = 17;
      static readonly int DILATE    = 18;


      // blend mode keyword definitions
      // @see processing.core.PImage#blendColor(int,int,int)

      public readonly static int REPLACE    = 0;
      public readonly static int BLEND      = 1 << 0;
      public readonly static int ADD        = 1 << 1;
      public readonly static int SUBTRACT   = 1 << 2;
      public readonly static int LIGHTEST   = 1 << 3;
      public readonly static int DARKEST    = 1 << 4;
      public readonly static int DIFFERENCE = 1 << 5;
      public readonly static int EXCLUSION  = 1 << 6;
      public readonly static int MULTIPLY   = 1 << 7;
      public readonly static int SCREEN     = 1 << 8;
      public readonly static int OVERLAY    = 1 << 9;
      public readonly static int HARD_LIGHT = 1 << 10;
      public readonly static int SOFT_LIGHT = 1 << 11;
      public readonly static int DODGE      = 1 << 12;
      public readonly static int BURN       = 1 << 13;

      // colour component bitmasks

      public static readonly int ALPHA_MASK = 0xff000000;
      public static readonly int RED_MASK   = 0x00ff0000;
      public static readonly int GREEN_MASK = 0x0000ff00;
      public static readonly int BLUE_MASK  = 0x000000ff;


      // for messages

      static readonly int CHATTER   = 0;
      static readonly int COMPLAINT = 1;
      static readonly int PROBLEM   = 2;


      // types of projection matrices

      static readonly int CUSTOM       = 0; // user-specified fanciness
      static readonly int ORTHOGRAPHIC = 2; // 2D isometric projection
      static readonly int PERSPECTIVE  = 3; // perspective matrix


      // shapes

      // the low four bits set the variety,
      // higher bits set the specific shape type

      //static readonly int GROUP           = (1 << 2);

      static readonly int POINT           = 2;  // shared with light (!)
      static readonly int POINTS          = 2;

      static readonly int LINE            = 4;
      static readonly int LINES           = 4;

      static readonly int TRIANGLE        = 8;
      static readonly int TRIANGLES       = 9;
      static readonly int TRIANGLE_STRIP  = 10;
      static readonly int TRIANGLE_FAN    = 11;

      static readonly int QUAD            = 16;
      static readonly int QUADS           = 16;
      static readonly int QUAD_STRIP      = 17;

      static readonly int POLYGON         = 20;
      static readonly int PATH            = 21;

      static readonly int RECT            = 30;
      static readonly int ELLIPSE         = 31;
      static readonly int ARC             = 32;

      static readonly int SPHERE          = 40;
      static readonly int BOX             = 41;


      // shape closing modes

      static readonly int OPEN = 1;
      static readonly int CLOSE = 2;


      // shape drawing modes

      /** Draw mode convention to use (x, y) to (width, height) */
      static readonly int CORNER   = 0;
      /** Draw mode convention to use (x1, y1) to (x2, y2) coordinates */
      static readonly int CORNERS  = 1;
      /** Draw mode from the center, and using the radius */
      static readonly int RADIUS   = 2;
      /** @deprecated Use RADIUS instead. */
      static readonly int CENTER_RADIUS = 2;
      /**
       * Draw from the center, using second pair of values as the diameter.
       * Formerly called CENTER_DIAMETER in alpha releases.
       */
      static readonly int CENTER   = 3;
      /**
       * Synonym for the CENTER constant. Draw from the center,
       * using second pair of values as the diameter.
       */
      static readonly int DIAMETER = 3;
      /** @deprecated Use DIAMETER instead. */
      static readonly int CENTER_DIAMETER = 3;


      // vertically alignment modes for text

      /** Default vertical alignment for text placement */
      static readonly int BASELINE = 0;
      /** Align text to the top */
      static readonly int TOP = 101;
      /** Align text from the bottom, using the baseline. */
      static readonly int BOTTOM = 102;


      // uv texture orientation modes

      /** texture coordinates in 0..1 range */
      static readonly int NORMAL     = 1;
      /** @deprecated use NORMAL instead */
      static readonly int NORMALIZED = 1;
      /** texture coordinates based on image width/height */
      static readonly int IMAGE      = 2;


      // text placement modes

      /**
       * textMode(MODEL) is the default, meaning that characters
       * will be affected by transformations like any other shapes.
       * <p/>
       * Changed value in 0093 to not interfere with LEFT, CENTER, and RIGHT.
       */
      static readonly int MODEL = 4;

      /**
       * textMode(SHAPE) draws text using the the glyph outlines of
       * individual characters rather than as textures. If the outlines are
       * not available, then textMode(SHAPE) will be ignored and textMode(MODEL)
       * will be used instead. For this reason, be sure to call textMode()
       * <EM>after</EM> calling textFont().
       * <p/>
       * Currently, textMode(SHAPE) is only supported by OPENGL mode.
       * It also requires Java 1.2 or higher (OPENGL requires 1.4 anyway)
       */
      static readonly int SHAPE = 5;


      // text alignment modes
      // are inherited from LEFT, CENTER, RIGHT


      // stroke modes

      static readonly int SQUARE   = 1 << 0;  // called 'butt' in the svg spec
      static readonly int ROUND    = 1 << 1;
      static readonly int PROJECT  = 1 << 2;  // called 'square' in the svg spec
      static readonly int MITER    = 1 << 3;
      static readonly int BEVEL    = 1 << 5;


      // lighting

      static readonly int AMBIENT = 0;
      static readonly int DIRECTIONAL  = 1;
      //static readonly int POINT  = 2;  // shared with shape feature
      static readonly int SPOT = 3;


      // key constants

      // only including the most-used of these guys
      // if people need more esoteric keys, they can learn about
      // the esoteric java KeyEvent api and of virtual keys

      // both key and keyCode will equal these values
      // for 0125, these were changed to 'char' values, because they
      // can be upgraded to ints automatically by Java, but having them
      // as ints prevented split(blah, TAB) from working
      static readonly char BACKSPACE = 8;
      static readonly char TAB       = 9;
      static readonly char ENTER     = 10;
      static readonly char RETURN    = 13;
      static readonly char ESC       = 27;
      static readonly char DELETE    = 127;

      // i.e. if ((key == CODED) && (keyCode == UP))
      static readonly int CODED     = 0xffff;

      // key will be CODED and keyCode will be this value
      static readonly int UP        = KeyEvent.VK_UP;
      static readonly int DOWN      = KeyEvent.VK_DOWN;
      static readonly int LEFT      = KeyEvent.VK_LEFT;
      static readonly int RIGHT     = KeyEvent.VK_RIGHT;

      // key will be CODED and keyCode will be this value
      static readonly int ALT       = KeyEvent.VK_ALT;
      static readonly int CONTROL   = KeyEvent.VK_CONTROL;
      static readonly int SHIFT     = KeyEvent.VK_SHIFT;


      // cursor types

      static readonly int ARROW = Cursor.DEFAULT_CURSOR;
      static readonly int CROSS = Cursor.CROSSHAIR_CURSOR;
      static readonly int HAND  = Cursor.HAND_CURSOR;
      static readonly int MOVE  = Cursor.MOVE_CURSOR;
      static readonly int TEXT  = Cursor.TEXT_CURSOR;
      static readonly int WAIT  = Cursor.WAIT_CURSOR;


      // hints - hint values are positive for the alternate version,
      // negative of the same value returns to the normal/default state

      static readonly int DISABLE_OPENGL_2X_SMOOTH    =  1;
      static readonly int ENABLE_OPENGL_2X_SMOOTH     = -1;
      static readonly int ENABLE_OPENGL_4X_SMOOTH     =  2;

      static readonly int ENABLE_NATIVE_FONTS         =  3;

      static readonly int DISABLE_DEPTH_TEST          =  4;
      static readonly int ENABLE_DEPTH_TEST           = -4;

      static readonly int ENABLE_DEPTH_SORT           =  5;
      static readonly int DISABLE_DEPTH_SORT          = -5;

      static readonly int DISABLE_OPENGL_ERROR_REPORT =  6;
      static readonly int ENABLE_OPENGL_ERROR_REPORT  = -6;

      static readonly int ENABLE_ACCURATE_TEXTURES    =  7;
      static readonly int DISABLE_ACCURATE_TEXTURES   = -7;

      static readonly int HINT_COUNT                  = 10;


      // error messages

      static readonly String ERROR_BACKGROUND_IMAGE_SIZE =
        "background image must be the same size as your application";
      static readonly String ERROR_BACKGROUND_IMAGE_FORMAT =
        "background images should be RGB or ARGB";

      static readonly String ERROR_TEXTFONT_NULL_PFONT =
        "A null PFont was passed to textFont()";

      static readonly String ERROR_PUSHMATRIX_OVERFLOW =
        "Too many calls to pushMatrix().";
      static readonly String ERROR_PUSHMATRIX_UNDERFLOW =
        "Too many calls to popMatrix(), and not enough to pushMatrix().";
    }
}
